package logic

import (
	"C/Rpc/internal/svc"
	"C/Rpc/model/redis"
	"C/Rpc/shop"
	"context"
	"math/rand"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 短信发送
func (l *SendSmsLogic) SendSms(in *shop.SendSmsRequest) (*shop.SendSmsResponse, error) {
	// todo: add your logic here and delete this line
	Code := rand.Intn(9000) + 1000

	//sms, err := pkg.SendSms(in.Phone, strconv.Itoa(Code))
	//if err != nil {
	//	return nil, err
	//}
	//if *sms.Body.Code != "OK" {
	//	return nil, fmt.Errorf(*sms.Body.Code)
	//}

	redis.Rdb.Set(context.Background(), "sms"+in.Source+in.Phone, Code, time.Minute*5)
	return &shop.SendSmsResponse{}, nil
}
